//使用pm2启动服务，如果开启多进程，这时就难以保障全局变量的唯一性，必须使用redis这类数据库进行持久化
//pm2 start app.js --max-memory-restart 20M
//pm2 stop
//pm2 monit
const express = require('express');
// 配置静态文件服务中间件
// server地址
const app = express();
const port = 8080;

var redis = require('redis');
const util = require('util');
var client = redis.createClient(6379, '192.168.21.176');
const get = util.promisify(client.get).bind(client);
const set = util.promisify(client.set).bind(client);

app.get('/', async (req, res) => {
  let num = await get('num');
  num++;
  await set('num', num);
  res.send('Hello World!' + num);
});

app.listen(port, function () {
  console.info(`server started in http://localhost:${port}`);
});
